package cn.xspace.wnx.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xspace.android.xafcommon.base.BaseFragment;
import com.xspace.android.xafcommon.been.BaseReturnBean;
import com.xspace.android.xafcommon.util.Constants;
import com.xspace.android.xafcommon.util.EventBusConstant;
import com.xspace.android.xafcommon.util.HypyUtil;
import com.xspace.android.xafcommon.util.LogUtil;
import com.xspace.android.xafcommon.util.T;
import com.xspace.android.xafcommon.view.dialog.ButtonClickListener;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.xspace.app.view.TitleBar;
import cn.xspace.chatui.bean.MsgRecordEntity;
import cn.xspace.library.bean.OrgDeptUserBean;
import cn.xspace.library.util.MyInfoUtil;
import cn.xspace.library.util.OkHttpManager;
import cn.xspace.wnx.R;
import cn.xspace.wnx.activity.MsgForwardActivity;
import cn.xspace.wnx.adapter.ContactListAdapter;
import cn.xspace.wnx.db.MyNewFriendDao;
import cn.xspace.wnx.db.OrgAllUserDao;
import cn.xspace.wnx.db.PreferencesDb;
import cn.xspace.wnx.util.ForwardHelper;
import cn.xspace.wnx.util.Navigator;
import cn.xspace.wnx.view.QuickAlphabeticBar;
import de.greenrobot.event.EventBus;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by liuchen on 2016/10/9.
 * <p>
 * 先获取本地数据，然后访问接口获取服务器数据m获取的数据不是全部返回的，而是将距上次最新获取的时间后有变化的数据
 */
public class AddressBookFragment extends BaseFragment implements View.OnClickListener {

    private static final String TAG = AddressBookFragment.class.getSimpleName();

    private QuickAlphabeticBar quickSeaech;
    private RelativeLayout searchRelative;
    private TextView searchEdit;
    private TextView serviceTv;
    private TextView tvFriendCount;
    private ListView contactListView;
    private RelativeLayout relativeOrgnize;
    private RelativeLayout relativeServiceObj;
    private RelativeLayout relativeWeiNong;
    private RelativeLayout relativeMyFriend;
    private RelativeLayout relativeMyGroup;
    private ArrayList<OrgDeptUserBean> mDataList;
    private ArrayList<OrgDeptUserBean> mTempList;
    private ContactListAdapter mAdapter;

    private boolean isGetData = false;
    //只有转发时才不会为null,用到此变量
    private MsgRecordEntity recordEntity;
    private String userId;
    private boolean isFarmer = false; //是否是农民,默认不是

    public static boolean refreshUnreadCount = false;
    private TitleBar mTitleBar;

    @Override
    public void onResume() {
        super.onResume();
        if (refreshUnreadCount) {
            refreshUnreadCount = false;
            getMyFriendUnReadCount();
        }
    }

    /**
     * 获取一个Fragment的实例
     *
     * @param bundle 传递的参数
     * @return
     */
    public static AddressBookFragment newInstance(Bundle bundle) {
//        Bundle args = new Bundle();
//        args.putString("schedule_id", schedule_id);
//        args.putString("table_name", table_name);
//        MessageFragment fragment = new MessageFragment();
        AddressBookFragment fragment = new AddressBookFragment();
        EventBus.getDefault().register(fragment);
        // 转发时才用到了该参数fragmentArgs
        fragment.setArguments(bundle); // 这里setArguments(bundle),在Base里将值传递给了fragmentArgs
        return fragment;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser && isGetData && !isFarmer) {
            mTempList.addAll(mDataList);
            requestNetWorkUpdateData();
        }
    }

    @Override
    protected void getIntentData() {
        super.getIntentData();
        if (fragmentArgs != null) { //通过转发打开的该界面才会传递该参数
            MsgRecordEntity msgRecordEntity = (MsgRecordEntity) fragmentArgs.getSerializable(MsgForwardActivity
                    .FORWARD_ENTITY);
            if (msgRecordEntity != null) {
                recordEntity = msgRecordEntity;
            }
        }
    }

    @Override
    public View initView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.fragment_addressbook, null, false);
    }

    @Override
    protected void initFindViewById(View view) {
        mTitleBar = (TitleBar) view.findViewById(R.id.address_title);
        mTitleBar.setLeftLayoutVisibility(View.GONE);
        quickSeaech = (QuickAlphabeticBar) view.findViewById(R.id.quickserach_cont_list);
        searchRelative = (RelativeLayout) view.findViewById(R.id.relative_search);
        contactListView = (ListView) view.findViewById(R.id.listview_contact);

        if ("1".equals(MyInfoUtil.getIsFarmer())) {
            isFarmer = true; //是农民,农民不显示搜索和头部
            searchRelative.setVisibility(View.GONE);
//            serviceTv.setText("我的农技员");
        }
        LinearLayout headLayout = (LinearLayout) LayoutInflater.from(mContext)
                .inflate(R.layout.list_view_header_address_books, null);
        if (!isFarmer) { //不是农民添加头布局
            contactListView.addHeaderView(headLayout);
        }
        relativeOrgnize = (RelativeLayout) headLayout.findViewById(R.id.header_organization);
        relativeServiceObj = (RelativeLayout) headLayout.findViewById(R.id.header_service_obj);
        LinearLayout linearLayout = (LinearLayout) headLayout.findViewById(R.id.layout_service_obj);
        relativeWeiNong = (RelativeLayout) headLayout.findViewById(R.id.header_weinong_orgnize);
        relativeMyFriend = (RelativeLayout) headLayout.findViewById(R.id.header_my_friend);
        tvFriendCount = (TextView) headLayout.findViewById(R.id.tv_friend_count); //我的好友申请个数
        serviceTv = (TextView) headLayout.findViewById(R.id.textview_service_obj);
        if (recordEntity != null) {
            linearLayout.setVisibility(View.GONE);
        }
        relativeWeiNong.setVisibility(View.GONE); // TODO 将该条目隐藏,避免删减代码时出错
        relativeMyGroup = (RelativeLayout) headLayout.findViewById(R.id.header_my_group);
        searchEdit = (TextView) view.findViewById(R.id.edit_search);
        relativeOrgnize.setOnClickListener(this);
        relativeServiceObj.setOnClickListener(this);

        relativeWeiNong.setOnClickListener(this);
        relativeMyFriend.setOnClickListener(this);
        relativeMyGroup.setOnClickListener(this);
        searchRelative.setOnClickListener(this);
        searchEdit.setOnClickListener(this);
        quickSeaech.init((TextView) view.findViewById(R.id.msm_cont_fast_position));
        quickSeaech.setListView(contactListView);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                quickSeaech.setHight(quickSeaech.getHeight());
                quickSeaech.setVisibility(View.VISIBLE);
            }
        }, 500);
        if (recordEntity != null) { //如果是转发打开的该界面,则不显示微农机构条目
            relativeWeiNong.setVisibility(View.GONE);
        }
    }

    @Override
    public void initData() {
        LogUtil.d(TAG, "initData");
        isGetData = true;
//        requestNetWorkUpdateData();
        mDataList = new ArrayList<>();
        mTempList = new ArrayList<>();
        mAdapter = new ContactListAdapter(mContext, mDataList, quickSeaech, false);
        contactListView.setAdapter(mAdapter);
        if (!isFarmer) { //不是农民,则正常加载
            getLocalData();
            getMyFriendUnReadCount();
        } else {
            requestNetWorkFarmerData();
        }
    }

    private void requestNetWorkFarmerData() {
        showWaitDialog();
        Map<String, Object> requestMap = new HashMap<>();
        userId = MyInfoUtil.getMyUserid(mContext);
        requestMap.put("user_id", userId);
        requestMap.put("plat_code", MyInfoUtil.getPlatCode());
        OkHttpManager.getInstance().commonRequest(Constants.QUERY_FARMER_SERVERS, requestMap)
                .subscribeOn(Schedulers.io())
                .map(new Func1<BaseReturnBean, List<OrgDeptUserBean>>() {
                    @Override
                    public List<OrgDeptUserBean> call(BaseReturnBean baseReturnBean) {
                        List<OrgDeptUserBean> dataList = new ArrayList<>();
                        try {
                            JSONArray jsonArray = new JSONArray(baseReturnBean.data);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                OrgDeptUserBean bean = new OrgDeptUserBean();
                                JSONObject single = jsonArray.getJSONObject(i);
                                bean.user_id = single.optString("user_id");
                                bean.user_name = single.optString("user_name");
                                bean.user_logo = single.optString("user_logo");
                                bean.dept_id = single.optString("dept_id");
                                bean.dept_name = single.optString("dept_name");
                                bean.org_id = single.optString("org_id");
                                bean.org_name = single.optString("org_name");
                                bean.user_sex = single.optString("user_sex");
                                bean.user_status = single.optInt("user_status");
                                bean.dept_id = single.optString("dept_id");
                                bean.dept_name = single.optString("dept_name");
//                                bean.user_orgid = single.optString("user_orgid");
//                                bean.user_orgname = single.optString("user_orgname");
                                bean.shotKey = HypyUtil.cn2py(bean.user_name);
                                dataList.add(bean);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        return dataList;
                    }
                })
                .doOnNext(new Action1<List<OrgDeptUserBean>>() {
                    @Override
                    public void call(List<OrgDeptUserBean> newList) {
                        if (newList.size() != 0) {
                            Collections.sort(newList, new Comparator<OrgDeptUserBean>() {
                                @Override
                                public int compare(OrgDeptUserBean lhs, OrgDeptUserBean rhs) {
                                    if (TextUtils.isEmpty(lhs.shotKey)) {
                                        return -1;
                                    }
                                    String key1 = lhs.shotKey.toUpperCase();
                                    Integer num1 = HypyUtil.chartSortMap.get(key1);
                                    String key2 = rhs.shotKey.toUpperCase();
                                    Integer num2 = HypyUtil.chartSortMap.get(key2);
                                    if (num1 == null) {
                                        return -1;
                                    }
                                    if (num2 == null) {
                                        return 1;
                                    }
                                    return num1.compareTo(num2);
                                }
                            });
                        }

                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<OrgDeptUserBean>>() {
                    @Override
                    public void onCompleted() {
                        LogUtil.d(TAG, "onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        hideWaitDialog();
                        e.printStackTrace();
                        T.showShort(mContext, e.getMessage());
                    }

                    @Override
                    public void onNext(List<OrgDeptUserBean> newList) {
                        hideWaitDialog();
                        mDataList.clear();
                        mDataList.addAll(newList);
                        mAdapter.initAlpha(mDataList);
                        mAdapter.notifyDataSetChanged();
                    }
                });
    }

    private void getMyFriendUnReadCount() {
        int unReadCount = MyNewFriendDao.getInstance().getUnReadCount();
        if (unReadCount > 0) {
            tvFriendCount.setText(unReadCount + "");
            tvFriendCount.setVisibility(View.VISIBLE);
        } else {
            tvFriendCount.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        contactListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    final OrgDeptUserBean bean = mDataList.get(position - contactListView.getHeaderViewsCount()); //去掉头布局
                    LogUtil.d(TAG, "wubaojie>>>" + "onItemClick: Position :" + position);
                    if (forward(bean)) return;
                    String userId = bean.user_id;
                    Navigator.startPersonCardActivity(mContext, userId);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private boolean forward(final OrgDeptUserBean bean) {
        if (recordEntity != null) { //转发时会弹出转发确认对话框
            if (TextUtils.equals(MyInfoUtil.getMyUserid(mContext), bean.user_id)) {
                T.showShort(mContext, R.string.cant_forward_toself);
                return true;
            }
            ForwardHelper.getInstance().confirmBeforeForward(mContext, new ButtonClickListener() {
                        @Override
                        public void buttonClick(View view) {
                            LogUtil.d("确认");
                            ForwardHelper.getInstance().sendMessageRecordSingleChat(mContext,
                                    recordEntity, bean);
                            Map<String, Object> fmap = new HashMap<String, Object>();
                            fmap.put(EventBusConstant.TYPE, EventBusConstant.FINISH_PAGE_FORWARD);
                            EventBus.getDefault().post(fmap);
                        }
                    },
                    recordEntity,
                    bean.user_name);
            //转发到此结束
            return true;
        }
        return false;
    }

    private void getLocalData() {
        //获取本地数据
        registerSubscription(
                OrgAllUserDao.getInstance().getOrgUserData().getOrgUserList()
                        .subscribeOn(Schedulers.io())
                        .doOnNext(new Action1<ArrayList<OrgDeptUserBean>>() {
                            @Override
                            public void call(ArrayList<OrgDeptUserBean> orgDeptUserBeenList) {
                                for (OrgDeptUserBean bean : orgDeptUserBeenList) {
                                    bean.shotKey = HypyUtil.cn2py(bean.user_name);
                                }
                                //根据拼音排序
                                Collections.sort(orgDeptUserBeenList, new Comparator<OrgDeptUserBean>() {
                                    @Override
                                    public int compare(OrgDeptUserBean lhs, OrgDeptUserBean rhs) {
                                        if (TextUtils.isEmpty(lhs.shotKey)) {
                                            return -1;
                                        }
                                        String key1 = lhs.shotKey.toUpperCase();
                                        Integer num1 = HypyUtil.chartSortMap.get(key1);
                                        String key2 = rhs.shotKey.toUpperCase();
                                        Integer num2 = HypyUtil.chartSortMap.get(key2);
                                        if (num1 == null) {
                                            return -1;
                                        }
                                        if (num2 == null) {
                                            return 1;
                                        }
                                        return num1.compareTo(num2);
                                    }
                                });
                            }
                        })
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<ArrayList<OrgDeptUserBean>>() {
                            @Override
                            public void onCompleted() {
                                LogUtil.d(TAG, "wubaojie>>>" + "onCompleted");
                            }

                            @Override
                            public void onError(Throwable e) {
                                e.printStackTrace();
                                LogUtil.d(TAG, "wubaojie>>>" + "onError"); //读取数据库出错
                            }

                            @Override
                            public void onNext(ArrayList<OrgDeptUserBean> o) {
                                LogUtil.d(TAG, "wubaojie>>>onNext: size : " + o.size());
                                for (OrgDeptUserBean bean : o) {
                                    LogUtil.d(TAG, "wubaojie>>>" + "onNext: shotKey : " + bean.shotKey);
                                }
//                                mDataList.addAll(o);
                                mTempList.addAll(o);
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        mDataList.clear();
                                        mDataList.addAll(mTempList);

                                        mAdapter.initAlpha(mDataList);
                                        mAdapter.notifyDataSetChanged();
                                    }
                                });

                                requestNetWorkUpdateData();
                            }
                        })
        );
    }

    /**
     * 通过网络获取数据更新本地数据库
     */
    private void requestNetWorkUpdateData() {
        Map<String, Object> requestMap = new HashMap<>();
        userId = MyInfoUtil.getMyUserid(mContext);
        requestMap.put("user_id", userId);
        requestMap.put("dept_id", MyInfoUtil.getUserOrgId());
        requestMap.put("lastUpdateTime", PreferencesDb.getInstance().queryPreferences(Constants.LAST_UPDATE_TIME));
        requestMap.put("lastDelTime", PreferencesDb.getInstance().queryPreferences(Constants.LAST_DEL_TIME));
        OkHttpManager.getInstance().commonRequest(Constants.QUERY_ORG_ALL_USERS, requestMap)
                .subscribeOn(Schedulers.io())
                .map(new Func1<BaseReturnBean, List<OrgDeptUserBean>>() {
                    @Override
                    public List<OrgDeptUserBean> call(BaseReturnBean baseReturnBean) {
                        LogUtil.d(TAG, "map>>>>");
                        JSONObject jsonSub;
                        List<OrgDeptUserBean> dataList = new ArrayList<>();
                        try {
                            jsonSub = new JSONObject(baseReturnBean.data);
                            JSONArray userArray = jsonSub.getJSONArray("userList");
                            String lastUpdateTime = jsonSub.optString("lastUpdateTime");
                            LogUtil.d(TAG, "lastUpdateTime>>" + lastUpdateTime);
//                            PreferencesUtils.setPfValue(mContext, Constants.LAST_UPDATE_TIME, lastUpdateTime,
// String.class.getName());
                            PreferencesDb.getInstance().savePreferences(Constants.LAST_UPDATE_TIME, lastUpdateTime);
                            String lastDelTime = jsonSub.optString("lastDelTime");
                            PreferencesDb.getInstance().savePreferences(Constants.LAST_DEL_TIME, lastDelTime);
//                            PreferencesUtils.setPfValue(mContext, Constants.LAST_DEL_TIME, lastDelTime, String
// .class.getName());
                            LogUtil.d(TAG, "lastDelTime>>" + lastDelTime);
                            for (int i = 0; i < userArray.length(); i++) {
                                JSONObject single = userArray.getJSONObject(i);
                                String user_id = single.optString("user_id");
                                String user_name = single.optString("user_name");
                                String user_logo = single.optString("user_logo");
                                String dept_id = single.optString("dept_id");
                                String user_sex = single.optString("user_sex");
                                String dept_name = single.optString("dept_name");
                                int user_status = single.optInt("user_status");
                                String key = HypyUtil.cn2py(user_name);
                                OrgDeptUserBean bean = new OrgDeptUserBean();
                                bean.user_id = user_id;
                                bean.user_name = user_name;
                                bean.user_logo = user_logo;
                                bean.user_sex = user_sex;
                                bean.dept_id = dept_id;
                                bean.dept_name = dept_name;
                                bean.user_status = user_status;
                                bean.shotKey = key;
                                dataList.add(bean);
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        return dataList;
                    }
                })
                .doOnNext(new Action1<List<OrgDeptUserBean>>() {
                    @Override
                    public void call(List<OrgDeptUserBean> newList) {
                        LogUtil.d(TAG, "ThreadId" + Thread.currentThread().getId());
                        List<OrgDeptUserBean> tempList = new ArrayList<>();
                        tempList.addAll(mTempList);
                        //更新本地数据
                        boolean isNewBeanExsit = false;
                        int indexOld = 0;
                        for (OrgDeptUserBean newBean : newList) {
                            for (OrgDeptUserBean oldBean : tempList) {
                                if (newBean.user_id != null && newBean.user_id.equals(oldBean.user_id)) {
                                    isNewBeanExsit = true;
                                    if (newBean.user_status == OrgDeptUserBean.UserStatus.Delete.toNumber()) {
                                        mTempList.remove(oldBean);
                                    } else if (newBean.user_status == OrgDeptUserBean.UserStatus.Update.toNumber()) {
                                        mTempList.set(indexOld, newBean);

                                    }
                                }
                                indexOld++;
                            }
                            //新添加的bean
                            if (!isNewBeanExsit && newBean.user_status != OrgDeptUserBean.UserStatus.Delete.toNumber
                                    ()) {
                                mTempList.add(newBean);
                            }
                            isNewBeanExsit = false;

                        }
                        LogUtil.d(TAG, "onNext>>>" + newList.size());
                        for (OrgDeptUserBean bean : newList) {
                            LogUtil.d(TAG, "onNext>>>>>>>>>" + bean.shotKey);
                        }
                        if (newList.size() != 0) {
                            Collections.sort(mTempList, new Comparator<OrgDeptUserBean>() {
                                @Override
                                public int compare(OrgDeptUserBean lhs, OrgDeptUserBean rhs) {
                                    if (TextUtils.isEmpty(lhs.shotKey)) {
                                        return -1;
                                    }
                                    String key1 = lhs.shotKey.toUpperCase();
                                    Integer num1 = HypyUtil.chartSortMap.get(key1);
                                    String key2 = rhs.shotKey.toUpperCase();
                                    Integer num2 = HypyUtil.chartSortMap.get(key2);
                                    if (num1 == null) {
                                        return -1;
                                    }
                                    if (num2 == null) {
                                        return 1;
                                    }
                                    return num1.compareTo(num2);
                                }
                            });
                        }

                    }
                })
                .doOnNext(new Action1<List<OrgDeptUserBean>>() {
                    @Override
                    public void call(List<OrgDeptUserBean> orgDeptUserBeen) {
                        for (OrgDeptUserBean bean : orgDeptUserBeen) {
                            OrgAllUserDao.getInstance().insertOrUpdate(bean);
                        }
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<OrgDeptUserBean>>() {
                    @Override
                    public void onCompleted() {
                        LogUtil.d(TAG, "onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        LogUtil.d(TAG, "onError");
                        mTempList.clear();
                        //网络请求出错读取数据库
                    }

                    @Override
                    public void onNext(List<OrgDeptUserBean> newList) {
                        if (newList.size() == 0) {
                            mTempList.clear();
                            return;
                        }
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mDataList.clear();
                                mDataList.addAll(mTempList);
                                mTempList.clear();
                                mAdapter.initAlpha(mDataList);
                                mAdapter.notifyDataSetChanged();
                            }
                        });

//            List<OrgDeptUserBean> tempList = new ArrayList<>();
//            tempList.addAll(mDataList);
//            //更新本地数据
//            boolean isNewBeanExsit = false;
//            int indexOld = 0;
//            for (OrgDeptUserBean newBean : newList) {
//                for (OrgDeptUserBean oldBean : tempList) {
//                    if (newBean.user_id != null && newBean.user_id.equals(oldBean.user_id)) {
//                        isNewBeanExsit = true;
//                        if (newBean.user_status == OrgDeptUserBean.UserStatus.Delete.toNumber()) {
//                            mDataList.remove(oldBean);
//                        } else if (newBean.user_status == OrgDeptUserBean.UserStatus.Update.toNumber()) {
//                            mDataList.set(indexOld, newBean);
//                        }
//                    }
//                    //新添加的bean
//                    if (!isNewBeanExsit) {
//                        mDataList.add(newBean);
//                    }
//                }
//                isNewBeanExsit = false;
//                indexOld++;
//            }
//            LogUtil.d(TAG, "onNext>>>" + newList.size());
//            for (OrgDeptUserBean bean : newList) {
//                LogUtil.d(TAG, "onNext>>>>>>>>>" + bean.shotKey);
//            }
//            mDataList = newList;
//            mAdapter = new ContactListAdapter(mContext, mDataList, quickSeaech);
//            contactListView.setAdapter(mAdapter);

                    }
                });
    }

//    Subscriber<List<OrgDeptUserBean>> dataRefresh =;
//    Subscriber<ArrayList<OrgDeptUserBean>> dataGet =;

    @Override
    public void onClick(View v) {
        if (recordEntity != null) {
            //转发
            Navigator.startHeaderActivity(mContext, v.getId(), fragmentArgs);
            return;
        }
        Navigator.startHeaderActivity(mContext, v.getId(), null);

//        switch (v.getId()) {
//            case R.id.header_organization://组织机构
//            case R.id.header_service_obj://服务对象
//            case R.id.header_weinong_orgnize://微农机构
//            case R.id.header_my_group:
//
//                break;
//            case R.id.edit_search:
//                Navigator.startUserSearchActivity(mContext);
//                break;
//
//        }
    }

    @Override
    public void onEventMainThread(Map<String, Object> inParam) {
        super.onEventMainThread(inParam);
        if (inParam == null)
            return;
        if (inParam.get(EventBusConstant.TYPE) == null)
            return;
        if (EventBusConstant.FINISH_PAGE_FORWARD.equals(inParam.get(EventBusConstant.TYPE)) && recordEntity != null) {
            exitActivity2();
        } else if ("UserInfoAct".equals(inParam.get(EventBusConstant.TYPE))) { //用户自己更改了头像
//            String operation = inParam.get(EventBusConstant.ACTION_KEY).toString();
//            if ("justRefreshingInfo".equals(operation)) {
//                String myLogo = (String) inParam.get(EventBusConstant.ACTION_VALUE);
//                for (OrgDeptUserBean orgDeptUserBean : mDataList) {
//                    if (orgDeptUserBean.user_id.equals(userId)) {
//                        orgDeptUserBean.user_logo = myLogo;
//                        break;
//                    }
//                }
//                mAdapter.notifyDataSetChanged();
//            }
        } else if (EventBusConstant.REFRESH_ADDRESSBOOK.equals(inParam.get(EventBusConstant.TYPE))) {
            contactListView.setSelection(contactListView.getFirstVisiblePosition());
            mTempList.addAll(mDataList);
            requestNetWorkUpdateData();
        } else if (EventBusConstant.NEW_FRIEND_PUSH.equals(inParam.get(EventBusConstant.TYPE))) {
            if (EventBusConstant.NEW_FRIEND_PUSH_BEAN.equals(inParam.get(EventBusConstant.ACTION_KEY))) {
                getMyFriendUnReadCount();
            }
        }
    }
}
